package com.api.shopapi.service.impl;

import com.api.shopapi.entity.Institution;
import com.api.shopapi.mapper.InstitutionMapper;
import com.api.shopapi.service.InstitutionService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("InstitutionServiceImplOne")
public class InstitutionServiceImpl implements InstitutionService {

    @Autowired
    private InstitutionMapper institutionMapper;

    @Override
    public int insert(Institution institution) {
        return institutionMapper.insert(institution);
    }

    @Override
    public int update(Institution institution) {
        return institutionMapper.update(institution);
    }

    @Override
    public int updateAddressAndLatLngAndType(Institution institution) {
        return institutionMapper.updateAddressAndLatLngAndType(institution);
    }

    @Override
    public int delete(String institutionCode) {
        return institutionMapper.delete(institutionCode);
    }

    @Override
    public Institution getByInstitutionCode(String institutionCode) {
        return institutionMapper.getByInstitutionCode(institutionCode);
    }

    @Override
    public
    Institution getByUserCode(String userCode){
        return institutionMapper.getByUserCode(userCode);
    }

    @Override
    public PageInfo<Institution> getPage(int pageIndex, int pageSize, String governmentCode) {
        PageHelper.startPage(pageIndex,pageSize);
        List<Institution> list = institutionMapper.listByGovernmentCode(governmentCode);
        return new PageInfo<>(list);
    }

    @Override
    public
    List<Institution> listByGovCode(String governmentCode){
        return institutionMapper.listByGovernmentCode(governmentCode);
    }

    @Override
    public
    List<Institution> listByGovCodeType(String governmentCode, int type){
        return institutionMapper.listByGovernmentCodeType(governmentCode,type);
    }

    @Override
    public
    PageInfo<Institution> pageByGovCodeName(int pageIndex, int pageSize,
                                            String governmentCode, String name){
        PageHelper.startPage(pageIndex,pageSize);
        List<Institution> list = institutionMapper.listByGovCodeName(governmentCode,name);
        return new PageInfo<>(list);
    }

}
